import { isObject } from '../sharde/utils'
import { mutableHandle } from './mutableHandle';

export function useReactive(target) {
  return createReactObject(target, mutableHandle);
}

function createReactObject(target, baseHandle) {
  if (!isObject(target)) {
    return target;
  }

  /**
   * baseHandle 以函数作为属性的对象，对象 target 各种操作时代理 p 行为
   */
  const observer = new Proxy(target, baseHandle);
  return observer
}